package com.zhuozhou.jdyc.main.main.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseViewHolder;
import com.zhuozhou.jdyc.databinding.BaterShopItemBinding;
import com.zhuozhou.jdyc.main.main.bean.BasicsCommodityTypeBean;
import com.zhuozhou.jdyc.util.apiUtil.NumberUtils;
import com.zhuozhou.jdyc.util.apiUtil.StringUtil;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:首页菜单adapter
 */
public class BarterShopAdapter extends BaseRecyclerViewAdapter<BasicsCommodityTypeBean.ArrayBean, BaterShopItemBinding> {
    public OnShopItemClickListener mOnShopItemClickListener;

    public BarterShopAdapter(Context context) {
        super(context);
    }

    public boolean isClassify = false;

    @Override
    protected int getLayoutId() {
        return R.layout.bater_shop_item;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder baseViewHolder, int pos) {
        super.onBindViewHolder(baseViewHolder, pos);
        baseViewHolder.getBinding().getRoot().setOnClickListener(v -> {
            if (mOnShopItemClickListener != null) {
                mOnShopItemClickListener.onShopItemClick(baseViewHolder.getBinding().getRoot(), getRealPosition(baseViewHolder));
            }
        });
    }

    @Override
    public void onBindHolder(BaseViewHolder<BaterShopItemBinding> holder, int pos) {
        if (StringUtil.isNotEmpty(mList.get(pos).getImages()) && mList.get(pos).getImages().contains("https")) {
            Glide.with(mContext).load(mList.get(pos).getImages()).into(holder.getBinding().imageMerchant);
        } else if (StringUtil.isNotEmpty(mList.get(pos).getImage()) && mList.get(pos).getImage().contains("https")) {
            Glide.with(mContext).load(mList.get(pos).getImage()).into(holder.getBinding().imageMerchant);
        } else
            Glide.with(mContext).load(mList.get(pos).getSpec_image()).into(holder.getBinding().imageMerchant);
        if (StringUtil.isEmpty(mList.get(pos).getNumber2()))
            mList.get(pos).setNumber2(mList.get(pos).getNumber());
        mList.get(pos).setLine_price(NumberUtils.decimalFormatInteger(mList.get(pos).getLine_price()));
        mList.get(pos).setGoods_price(NumberUtils.decimalFormatInteger(mList.get(pos).getGoods_price()));
        holder.getBinding().setShop(mList.get(pos));
        if (isClassify) {
            holder.getBinding().llSee.setVisibility(View.GONE);
            holder.getBinding().tvTitle.setVisibility(View.VISIBLE);
            holder.getBinding().llTitle.setVisibility(View.GONE);
        }
    }

    public void setIsClassify(boolean b) {
        isClassify = b;
    }

    public void setOnShopItemClickListener(OnShopItemClickListener l) {
        mOnShopItemClickListener = l;
    }

    public interface OnShopItemClickListener {
        void onShopItemClick(View view, int position);
    }
}
